// import { resultEn, sysDictTree } from "../api/system";
import { sysDictTree } from "../api/system";

// interface IGlobalData {
//   systemEnum: any;
//   systemDict: any;
// }

const globalData = {
  systemEnum: [],
  systemDict: [],
};

export function setGlobalData(key, value) {
  globalData[key] = value;
}

export function getGlobalData(key) {
  console.log(globalData);
  return globalData.systemDict[key];
}

export function getSystemEnumValue(globalDataKey, key) {
  return globalData.systemEnum[globalDataKey]?.find(
    (item) => item?.code == key
  );
}

export function getSystemDictValue(globalDataKey, key) {
  return globalData.systemDict[globalDataKey]?.find(
    (item) => item?.code == key
  );
}

export async function initGlobalData() {
  // const systemEnum = await resultEn();
  const systemDict = await sysDictTree();

  // setGlobalData("systemEnum", systemEnum?.data || []);
  setGlobalData("systemDict", systemDict?.data || []);
}

export default function clearGlobalData() {
  setGlobalData("systemEnum", []);
  setGlobalData("systemDict", []);
}
